import { defineStore } from 'pinia';
import DeviceApi from "@/sheep/api/device/device";

const device = defineStore({
  id: 'device',
  state: () => ({
    deviceId: DeviceApi.getDeviceSerial(),
    deviceInfo: {}, // 设备信息
  }),

  actions: {
    async getDeviceInfo() {
      try {
        const { code, data } = await DeviceApi.getDeviceInfo(this.deviceId);
        if (code === 0) {
          this.deviceInfo = data
          return Promise.resolve(data);
        }
        return Promise.reject(data);
      } catch (err) {
        return Promise.reject(err);
      }
    },
  },
  persist: {
    enabled: true,
    strategies: [{
      key: 'device-store',
    }],
  },
});

export default device;